package com.zhang.family_doctor.controller;

import com.zhang.family_doctor.entity.Purview;
import com.zhang.family_doctor.entity.R;
import com.zhang.family_doctor.service.PurviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 权限模块
 */
@Api(tags = "权限模块相关接口")
@RestController
@RequestMapping("/purview")
@Slf4j
public class PurviewController {

    @Autowired
    private PurviewService purviewService;

    @ApiOperation("新增权限")
    @PostMapping("/save")
    public R<String> save(@RequestBody Purview purview){
        log.info("新增权限：{}",purview);
        return purviewService.save(purview);
    }

    @ApiOperation("修改权限")
    @PostMapping("/update")
    public R<String> update(@RequestBody Purview purview){
        log.info("修改权限：{}",purview);
        return purviewService.update(purview);
    }

    @ApiOperation("查看所有的权限")
    @GetMapping("/getAll")
    public R<List<Purview>> getAll(){
        log.info("查看所有的权限：");
        return purviewService.getAll();
    }

    @ApiOperation("根据id删除权限")
    @DeleteMapping("/deleteById")
    public R<String> deleteById(Integer id){
        log.info("根据id删除权限：{}",id);
        return purviewService.deleteById(id);
    }
}
